home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / graphics / graphics_init.c < prev    next >
C/C++ Source or Header  |  1996-10-31  |  4KB  |  196 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: graphics_init.c,v 1.6 1996/10/31 11:11:52 aros Exp $
  4.  
  5.     Desc: Graphics library
  6.     Lang: english
  7. */
  8. #include <exec/resident.h>
  9. #include <clib/exec_protos.h>
  10. #include <aros/libcall.h>
  11. #include <dos/dos.h>
  12. #include <exec/execbase.h>
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/text.h>
  15. #include <clib/graphics_protos.h>
  16. #include "graphics_intern.h"
  17.  
  18. static const char name[];
  19. static const char version[];
  20. static const APTR inittabl[4];
  21. static void *const Graphics_functable[];
  22. struct GfxBase * AROS_SLIB_ENTRY(init,Graphics)();
  23. extern const char Graphics_end;
  24.  
  25. extern int  driver_init (struct GfxBase *);
  26. extern int  driver_open (struct GfxBase *);
  27. extern void driver_close (struct GfxBase *);
  28. extern void driver_expunge (struct GfxBase *);
  29.  
  30. int Graphics_entry(void)
  31. {
  32.     /* If the library was executed by accident return error code. */
  33.     return -1;
  34. }
  35.  
  36. const struct Resident Graphics_resident=
  37. {
  38.     RTC_MATCHWORD,
  39.     (struct Resident *)&Graphics_resident,
  40.     (APTR)&Graphics_end,
  41.     RTF_AUTOINIT,
  42.     39,
  43.     NT_LIBRARY,
  44.     0,
  45.     (char *)name,
  46.     (char *)&version[6],
  47.     (ULONG *)inittabl
  48. };
  49.  
  50. static const char name[]=GRAPHICSNAME;
  51.  
  52. static const char version[]="$VER: graphics.library 39.0 (12.8.96)\n\015";
  53.  
  54. static const APTR inittabl[4]=
  55. {
  56.     (APTR)sizeof(struct GfxBase),
  57.     (APTR)Graphics_functable,
  58.     NULL,
  59.     &AROS_SLIB_ENTRY(init,Graphics)
  60. };
  61.  
  62. #ifndef SYSFONTNAME
  63. #   define SYSFONTNAME    "topaz.font"
  64. #endif
  65.  
  66. static struct TextAttr sysTA;
  67.  
  68. AROS_LH2(struct GfxBase *, init,
  69.  AROS_LHA(struct GfxBase *, GfxBase, D0),
  70.  AROS_LHA(BPTR,               segList,   A0),
  71.        struct ExecBase *, sysBase, 0, Graphics)
  72. {
  73.     AROS_LIBFUNC_INIT
  74.  
  75.     SysBase = sysBase;
  76.  
  77.     if (!driver_init (GfxBase))
  78.     return NULL;
  79.  
  80.     /* You would return NULL if the init failed */
  81.     return GfxBase;
  82.     AROS_LIBFUNC_EXIT
  83. }
  84.  
  85. AROS_LH1(struct GfxBase *, open,
  86.  AROS_LHA(ULONG, version, D0),
  87.        struct GfxBase *, GfxBase, 1, Graphics)
  88. {
  89.     AROS_LIBFUNC_INIT
  90.     struct TextFont * def;
  91.  
  92.     /* Keep compiler happy */
  93.     version=0;
  94.  
  95.     if (!GfxBase->DefaultFont)
  96.     {
  97.     sysTA.ta_Name  = (STRPTR)SYSFONTNAME;
  98.     sysTA.ta_YSize = 8;
  99.     sysTA.ta_Style = FS_NORMAL;
  100.     sysTA.ta_Flags = 0;
  101.  
  102.     def = OpenFont (&sysTA);
  103.  
  104.     if (!def)
  105.         return NULL;
  106.  
  107.     GfxBase->DefaultFont = def;
  108.     sysTA.ta_YSize = def->tf_YSize;
  109.     }
  110.  
  111.     if (!driver_open (GfxBase))
  112.     return NULL;
  113.  
  114.     /* I have one more opener. */
  115.     GfxBase->LibNode.lib_OpenCnt++;
  116.     GfxBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  117.  
  118.     /* You would return NULL if the open failed. */
  119.     return GfxBase;
  120.     AROS_LIBFUNC_EXIT
  121. }
  122.  
  123. AROS_LH0(BPTR, close,
  124.        struct GfxBase *, GfxBase, 2, Graphics)
  125. {
  126.     AROS_LIBFUNC_INIT
  127.  
  128.     /* I have one fewer opener. */
  129.     if(!--GfxBase->LibNode.lib_OpenCnt)
  130.     {
  131.     driver_close (GfxBase);
  132.  
  133.     /* Delayed expunge pending? */
  134.     if(GfxBase->LibNode.lib_Flags&LIBF_DELEXP)
  135.         /* Then expunge the library */
  136.         return expunge();
  137.     }
  138.     return 0;
  139.     AROS_LIBFUNC_EXIT
  140. }
  141.  
  142. AROS_LH0(BPTR, expunge,
  143.        struct GfxBase *, GfxBase, 3, Graphics)
  144. {
  145.     AROS_LIBFUNC_INIT
  146. #ifndef DISK_BASED
  147.     if (!(GfxBase->LibNode.lib_OpenCnt) )
  148.     {
  149.     if (GfxBase->DefaultFont)
  150.     {
  151.         CloseFont (GfxBase->DefaultFont);
  152.  
  153.         GfxBase->DefaultFont = NULL;
  154.     }
  155.  
  156.     /* Allow the driver to release uneccessary memory */
  157.     driver_expunge (GfxBase);
  158.     }
  159.  
  160.     /* Don't delete this library. It's in ROM and therefore cannot be
  161.        deleted */
  162.     return 0L;
  163. #else
  164.     BPTR ret;
  165.  
  166.     /* Test for openers. */
  167.     if (GfxBase->LibNode.lib_OpenCnt)
  168.     {
  169.     /* Set the delayed expunge flag and return. */
  170.     GfxBase->LibNode.lib_Flags|=LIBF_DELEXP;
  171.     return 0;
  172.     }
  173.  
  174.     /* Get rid of the library. Remove it from the list. */
  175.     Remove(&GfxBase->LibNode.lib_Node);
  176.  
  177.     /* Get returncode here - FreeMem() will destroy the field. */
  178.     ret=0L;
  179.  
  180.     /* Free the memory. */
  181.     FreeMem((char *)GfxBase-GfxBase->LibNode.lib_NegSize,
  182.         GfxBase->LibNode.lib_NegSize+GfxBase->LibNode.lib_PosSize);
  183.  
  184.     return ret;
  185. #endif
  186.     AROS_LIBFUNC_EXIT
  187. }
  188.  
  189. AROS_LH0I(int, null,
  190.         struct GfxBase *, GfxBase, 4, Graphics)
  191. {
  192.     AROS_LIBFUNC_INIT
  193.     return 0;
  194.     AROS_LIBFUNC_EXIT
  195. }
  196.